[HVM] Fix hvm_copy_[to|from]_guest_virt
authorTim Deegan <Tim.Deegan@xensource.com>
Fri, 24 Nov 2006 09:42:40 +0000 (09:42 +0000)
committerTim Deegan <Tim.Deegan@xensource.com>
Fri, 24 Nov 2006 09:42:40 +0000 (09:42 +0000)
which would fail if it crossed a page boundary where the guest physical
pages were not contiguous.
Signed-off-by: Tim Deegan <Tim.Deegan@xensource.com>
xen/arch/x86/hvm/hvm.c

index 0aa31540cc00e390d02d33f4d8d18bbb43b319f5..40b025277fb740739598f34bf6b6d5ef25c5613c 100644 (file)
@@ -330,12 +330,13 @@ void hvm_hlt(unsigned long rflags)
 /*
  * __hvm_copy():
  *  @buf  = hypervisor buffer
- *  @addr = guest physical address to copy to/from
+ *  @addr = guest address to copy to/from
  *  @size = number of bytes to copy
  *  @dir  = copy *to* guest (TRUE) or *from* guest (FALSE)?
+ *  @virt = addr is *virtual* (TRUE) or *guest physical* (FALSE)?
  * Returns number of bytes failed to copy (0 == complete success).
  */
-static int __hvm_copy(void *buf, paddr_t addr, int size, int dir)
+static int __hvm_copy(void *buf, paddr_t addr, int size, int dir, int virt)
 {
     unsigned long mfn;
     char *p;
@@ -346,7 +347,11 @@ static int __hvm_copy(void *buf, paddr_t addr, int size, int dir)
     {
         count = min_t(int, PAGE_SIZE - (addr & ~PAGE_MASK), todo);
 
-        mfn = get_mfn_from_gpfn(addr >> PAGE_SHIFT);
+        if ( virt )
+            mfn = get_mfn_from_gpfn(shadow_gva_to_gfn(current, addr));
+        else
+            mfn = get_mfn_from_gpfn(addr >> PAGE_SHIFT);
+
         if ( mfn == INVALID_MFN )
             return todo;
 
@@ -369,24 +374,25 @@ static int __hvm_copy(void *buf, paddr_t addr, int size, int dir)
 
 int hvm_copy_to_guest_phys(paddr_t paddr, void *buf, int size)
 {
-    return __hvm_copy(buf, paddr, size, 1);
+    return __hvm_copy(buf, paddr, size, 1, 0);
 }
 
 int hvm_copy_from_guest_phys(void *buf, paddr_t paddr, int size)
 {
-    return __hvm_copy(buf, paddr, size, 0);
+    return __hvm_copy(buf, paddr, size, 0, 0);
 }
 
 int hvm_copy_to_guest_virt(unsigned long vaddr, void *buf, int size)
 {
-    return __hvm_copy(buf, shadow_gva_to_gpa(current, vaddr), size, 1);
+    return __hvm_copy(buf, vaddr, size, 1, 1);
 }
 
 int hvm_copy_from_guest_virt(void *buf, unsigned long vaddr, int size)
 {
-    return __hvm_copy(buf, shadow_gva_to_gpa(current, vaddr), size, 0);
+    return __hvm_copy(buf, vaddr, size, 0, 1);
 }
 
+
 /* HVM specific printbuf. Mostly used for hvmloader chit-chat. */
 void hvm_print_line(struct vcpu *v, const char c)
 {